package com.wyh.security.gfive.service;

import com.wyh.common.constant.Constants;
import com.wyh.domain.po.gfive.Role;
import com.wyh.domain.po.gfive.User;
import com.wyh.service.gfive.PermissionsService;
import com.wyh.service.gfive.RoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
* @author 32276
* @description 针对表【permissions(权限表)】的数据库操作Service实现
* @createDate 2024-05-20 09:55:57
*/
@Service
public class PermissionsServiceSecurityImpl
    {

    @Autowired
    private RoleService roleService;

 @Autowired
 private PermissionsService permissionsService;

    public Set<String> getMenuPermission(User user) {
        Set<String>  perms= new HashSet<String>();
         if(user.getId()==1){
             perms.add(Constants.ALL_PERMISSION);
         }else {
             List<Role> roles= roleService.selectRoleByUserId(user.getId());
             for(Role role:roles){
                 Set<String> rolePerms= permissionsService.selectPermsByRoleId(role.getId());
                 perms.addAll(rolePerms);
             }

         }

        return perms;
    }

}




